class TFCommanderFlagRed extends actor;

var byte TeamNum;
var UnrealPawn      Holder;
var bool bHeld;

var float lastfx;

replication
{
    reliable if (Role == ROLE_Authority)
        bHeld, lastFx;
}

simulated function PostBeginPlay()
{
    local gamereplicationinfo gri;

    Super.PostBeginPlay();
    LoopAnim('flag',0.8);
    SimAnim.bAnimLoop = true;
    gri=level.Game.GameReplicationInfo;
	if ( (GRI != None) && (TeamNum < 2) && (GRI.TeamSymbols[TeamNum] != None) )
	    TexScaler(Combiner(Shader(FinalBlend(Skins[0]).Material).Diffuse).Material2).Material = GRI.TeamSymbols[TeamNum];
}

function timer()
{
    local pawn p;
    local tfcommanderfx fx;
    local tfaurafx aura;

    /*if(aura==none && !auraready)
    {
        if(teamnum==0) aura=spawn(class'taskforces.tfcommanderaura',p,,p.location-vect(0,0,1)*29,rot(1,0,0)*-16384);
        else aura=spawn(class'taskforces.tfcommanderauraB',p,,p.location-vect(0,0,1)*29,rot(1,0,0)*-16384);
        aura.setbase(p);
        //aura.SetRotation(rot(1,0,0)*-16384);

        auraready=true;
    }*/

    foreach CollidingActors(class'pawn',p,1200,holder.location)
    {
            if(p!=holder && p.health>0 && p.PlayerReplicationInfo!=none && p.PlayerReplicationInfo.team.teamindex==teamnum && FastTrace(p.Location, holder.Location))
            {
                tfpri(p.PlayerReplicationInfo).inAura=true;
                tfpri(p.PlayerReplicationInfo).AuraEndTime=level.timeseconds+0.2;

                if(teamnum==0) aura=spawn(class'taskforces.tfauraFX',p,,p.location-vect(0,0,1)*32,rot(0,1,0)*16384);
                else aura=spawn(class'taskforces.tfauraFXB',p,,p.location-vect(0,0,1)*32,rot(0,1,0)*16384);
                aura.setbase(p);
            }
    }

    bHidden=tfpri(holder.playerreplicationinfo).shifted || xpawn(holder).bInvis;

    if(bHidden || level.timeseconds-lastfx<0.3) return;

    lastfx=level.timeseconds;

    if(teamnum==0) fx=spawn(class'taskforces.tfcommanderfx',holder,,holder.location-vect(0,0,1)*29,rot(0,1,0)*16384);
    else fx=spawn(class'taskforces.tfcommanderfxB',holder,,holder.location-vect(0,0,1)*29,rot(0,1,0)*16384);

    if(fx!=none) fx.setbase(holder);
}

function SetHolder(Controller C)
{
    Holder = UnrealPawn(C.Pawn);
    bOnlyDrawIfAttached = true;
    bCollideWorld = false;
    SetCollision(false, false, false);
	SetBase(holder);
	holder.AttachToBone(self,'FlagHand');
	SetRelativeRotation(holder.GameObjRot);
	SetRelativeLocation(holder.GameObjOffset);
    bHeld=true;
    Settimer(0.1,true);
}

function tick(float deltatime)
{
    if(bHeld && (holder==none || holder.health<=0))
        destroy();

    super.Tick(deltatime);
}

defaultproperties
{
     LightEffect=LE_QuadraticNonIncidence
     LightSaturation=64
     DrawType=DT_Mesh
     bAlwaysZeroBoneOffset=True
     Physics=PHYS_Trailer
     NetUpdateFrequency=10.000000
     Mesh=VertMesh'XGame_rc.FlagMesh'
     DrawScale=0.800000
     PrePivot=(X=2.000000,Z=0.500000)
     Skins(0)=FinalBlend'XGameShaders.RedFlagShader_F'
     AmbientGlow=128
     Style=STY_Masked
     bOwnerNoSee=True
     bUseCylinderCollision=True
}
